<?php

declare(strict_types=1);

/**
 * @Author:     Frank
 * @contact     frank_hhm@163.com
 * @Date:       2022-12-28 18:54:52
 * @Last Modified time: 2022-12-29 15:49:07
 */
namespace app\common\model\store;

use frank\base\BaseModel;
use frank\traits\ModelTrait;
use frank\utils\helper\ArrayHelper;
use app\common\enum\EnumFactory;

/**
 * 商品规格
 * Class GoodsSpecModel
 * @package app\common\model\store
 */
class GoodsSpecModel extends BaseModel
{
    use ModelTrait;

    /**
     * 数据表主键
     */
    protected $pk = 'id';

    /**
     * 模型名称
     */
    protected $name = 'store_goods_spec';

    /**
     * 关联商品规格属性
     */
    public function value(){
        return $this->hasMany(GoodsSpecValueModel::class,'spec_id','id');
    }

    /**
     * id搜索器
     */
    public function searchIdAttr($query, $value)
    {
        if (is_array($value)) {
            $query->whereIn('id', $value);
        } else {
            $query->where('id', $value);
        }
    }

    /**
     * goodsid搜索器
     */
    public function searchGoodsIdAttr($query, $value)
    {
        if (is_array($value)) {
            $query->whereIn('goods_id', $value);
        } else {
            $query->where('goods_id', $value);
        }
    }
}
